﻿using OpenQA.Selenium;
using System;
using System.Collections.Generic;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;

namespace FAfx.Selenium.Pages
{
    internal static class IPageObjectExtensions
    {
        public static void GotoToUrl(this IPageObject page)
        {
            page.Driver.Navigate().GoToUrl(page.Url);
        }

        public static void TakeSnapshot(this IPageObject page, string fileName)
        {
            const string SCREENSHOT_FILE = @"{0}.{1:yyMMdd_HHmmss}.png";

            ITakesScreenshot screenshotDriver = page.Driver as ITakesScreenshot;
            Screenshot screenshot = screenshotDriver.GetScreenshot();
            var saveLocation = string.Format(SCREENSHOT_FILE, fileName, DateTime.Now);
            screenshot.SaveAsFile(saveLocation, ImageFormat.Png);
        }
    }
}
